package com.zr.gdms.daoimpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.mysql.jdbc.MiniAdmin;
import com.zr.gdms.dao.CourseAdjustdao;
import com.zr.gdms.model.Course;
import com.zr.gdms.model.Score;
import com.zr.gdms.model.Student;
import com.zr.gdms.util.JDBCUtil;

public class CourseAdjustdaoimpl implements CourseAdjustdao {
/**
 * 修改课题状态
 * */
	@Override
	public boolean NoCourseAdjust(int cid, String cstate) {
		// TODO Auto-generated method stub
		boolean flag=false;
		StringBuffer sq1=new StringBuffer();
		sq1.append(" update course set cstate=?");
		sq1.append(" where cid=?");
		Connection con=JDBCUtil.getConnection();
		try {
			PreparedStatement pst=con.prepareStatement(sq1.toString());
			pst.setString(1, cstate);
			pst.setInt(2, cid);
			int i=pst.executeUpdate();
			if(i>0){
				flag=true;
			}	
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
		return flag;
	}
/**
 * 查找课题编号通过SID
 * */
	@Override
	public int SelectCourseCid(int sid) {
		// TODO Auto-generated method stub
		int cid = 0;
		StringBuffer sq=new StringBuffer("");
		sq.append(" SELECT score.cid");
		sq.append(" FROM score");
		sq.append(" INNER JOIN student");
		sq.append(" ON student.sid=score.sid");
		sq.append(" WHERE student.sid=?");
		Connection con=JDBCUtil.getConnection();
		try {
			PreparedStatement pst1=con.prepareStatement(sq.toString());
			pst1.setInt(1, sid);
			ResultSet rs=pst1.executeQuery();
			while(rs.next()){
			
				cid=rs.getInt("cid");
				
			}
		
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
		return cid;
	}
	
}
		
		
		
		
		
	
